package com.sunsys.mapreduce.poc1.filerecords.validation;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.ClusterStatus;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Mapper;

public class FileRecordsValidationMapper extends Mapper<LongWritable, Text, Text, Text> {

	private String fileName = null;
	private final String RECORDS_COUNT = "RECORDS_COUNT";
	
	public FileRecordsValidationMapper() {
	}

	@Override
	protected void setup(Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
		fileName = "FileName1";
	}
	
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context)
			throws IOException, InterruptedException {
		
		Counter counter = context.getCounter(fileName, RECORDS_COUNT);
		counter.increment(1);
		
		
		
	}

	@Override
	protected void cleanup(Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
		
		Counter counter = context.getCounter(fileName, RECORDS_COUNT);
		context.write(new Text(fileName), new Text("Number of records:"+counter.getValue()));
	}
}
